package main

import "os"
import "bufio"
import "fmt"
import "io/ioutil"

func check(e error) {
    if e != nil {
        panic(e)
    }
}

func main() {
    d1 := []byte("hello \n go\n")
    err := ioutil.WriteFile("./tmp/txt.tx", d1, 0644)
    check(err)
    f, err := os.Create("./tmp/2.tx")
    check(err)
  
    defer f.Close()

    d2 := []byte{115, 111, 109, 101, 10}
    n2, err := f.Write(d2)
    check(err)
    fmt.Printf("worte %d bytes\n", n2)
    

    n3, err := f.WriteString("writes \n")
    fmt.Printf("worte %d bytes\n", n3)
    check(err)
    f.Sync()
    
    w := bufio.NewWriter(f)
    n4, err := w.WriteString("buffered \n")
    check(err)
    fmt.Printf("wrote %d bytes \n", n4)
     w.Flush()
}
